
$(document).ready(function(){
    // render
    loadData();
    // event
    bindEventEdit();
});

function loadData() {
    var _maDMBV = ISS.SESSION.getSession('session_maDMBV');

    var category = {};
    category.maDMBV = _maDMBV;
    ISS.BACKEND.request({
        url: ISS.SESSION.getSession('contextPath') + '/service/admin/editPostCategory',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(category),
        success: function (data) {
            var responseContent = data.responseObject;
            loadDataComplete(responseContent);
        }
    });
}

function loadDataComplete(category){
    ISS.DOM.setVal('#AdPostCategory_code', category.maDMBV);
    ISS.DOM.setVal('#AdPostCategory_name', category.tenDM);
}

function bindEventEdit(){
    ISS.EVENT.bindEvent('#AdPostCategory_Modified1', 'click', function () {
        sendInfoEdit();
    });
}

function sendInfoEdit() {
    var category = {};
    category.maDMBV = ISS.DOM.getVal('#AdPostCategory_code');
    category.tenDM = ISS.DOM.getVal('#AdPostCategory_name');

    ISS.BACKEND.request({
        url: ISS.SESSION.getSession('contextPath') + '/service/admin/registerPostCategoryEdit',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(category),
        success: function (data) {
            var responseContent = data.responseObject;
            sendInfoEditComplete(responseContent);
        }
    });
}

function sendInfoEditComplete(color) {
    if(color) {
        ISS.WINDOW.location('/jsp/admin/ad-post-category-common.jsp');
    }
    else{
        alert('Cập nhật không thành công');
    }
}
